package com.horse.cloud.boss.service;

import com.horse.cloud.boss.feignclients.GatewayClient;
import com.horse.cloud.data.domain.gateway.BusinessSystemBo;
import com.horse.cloud.data.domain.gateway.BusinessSystemQueryBo;
import com.horse.cloud.data.domain.gateway.GatewayServerQueryBo;
import com.horse.cloud.framework.base.BaseService;
import com.horse.cloud.framework.general.enums.ResponseCodeEnums;
import com.horse.cloud.framework.general.response.Response;
import com.horse.cloud.framework.general.validator.BoValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @create : Created by intelliJ IDEA 17.2
 * @author : bing.Pan
 * @e-mail : 15923508369@163.com
 * @gmdate : 02 16 2018 21:47
 * @sidesc :
 */
@Service
public class GatewayService  extends BaseService {

    @Autowired private GatewayClient gatewayClient;

    public Response findBussinessSystemById(String id) {
        if(StringUtils.isEmpty(id)){
            return new Response(ResponseCodeEnums.CLIENT_PARAM_PARSE_ERROR,"ID不能为空");
        }
        return gatewayClient.findBussinessSystemById(id);
    }



    public Response addAndUpdate(BusinessSystemBo businessSystemBo) {

        String validateEntity = BoValidator.validateEntity(businessSystemBo);
        if(!StringUtils.isEmpty(validateEntity)){
            return new Response(ResponseCodeEnums.CLIENT_PARAM_PARSE_ERROR,validateEntity);
        }
        Response response = gatewayClient.addAndUpdate(businessSystemBo);
        if(response.getCode() != ResponseCodeEnums.SUCCESS.getCode()){
            return new Response(ResponseCodeEnums.SERVER_UNKNOWN_ERROR);
        }
        return new Response<>();
    }


    public Response deleteBusinessSystem(String id) {
        return gatewayClient.deleteBusinessSystem(id);
    }

    public Response businessSystemList(BusinessSystemQueryBo businessSystemQueryBo) {
        return gatewayClient.businessSystemList(businessSystemQueryBo);
    }








    public Response serverList(GatewayServerQueryBo gatewayServerQueryBo) {
        return gatewayClient.serverList(gatewayServerQueryBo);
    }


}
